package com.hzmg.handler.http;

import akka.actor.typed.Behavior;
import akka.actor.typed.javadsl.AbstractBehavior;
import akka.actor.typed.javadsl.ActorContext;
import akka.actor.typed.javadsl.Behaviors;
import akka.actor.typed.javadsl.Receive;
import com.hzmg.akkacloud.common.serialize.JsonUtils;
import com.hzmg.akkacloud.common.serialize.SerializerUtils;
import com.hzmg.route.AkkaResponseEntity;
import com.hzmg.route.Shift;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class AkkaHttpWriteResponseHandler extends AbstractBehavior<Shift> {

    private static final Logger logger = LoggerFactory.getLogger(AkkaHttpWriteResponseHandler.class);


    public AkkaHttpWriteResponseHandler(ActorContext<Shift> context) {
        super(context);
    }

    public static Behavior<Shift> create() {
        return Behaviors.setup(context -> new AkkaHttpWriteResponseHandler(context));
    }

    @Override
    public Receive<Shift> createReceive() {
        return newReceiveBuilder()
                .onMessage(AkkaResponseEntity.class, this::onResponse)
                .build();
    }

    private Behavior<Shift> onResponse(AkkaResponseEntity response) {
        logger.info("[akkacloud-gateway-core] AkkaHttpWriteResponseFilter response: {}"
                , JsonUtils.toJSONString(JsonUtils.toJSONString(response.req
                        .entity())));
        //TODO: 响应数据格式
        //TODO: 返回响应信息至客户端
        return Behaviors.stopped();
    }
}
